//
// Created by yunnan xu on 2020/11/17.
//

#include "Buffer.h"
#include <memory>
#include <gles3/gl32.h>
#include "EngineCore.h"
#include "GLESUtils.h"


VertexBuffer<GraphicsAPI::GLESv3>::VertexBuffer(GLenum buffer_target, GLenum usage, long offset, long size, const void * data) {
    GL_CHECK(glGenBuffers(1, &buffer));
    GL_CHECK(glBindBuffer(buffer_target, buffer));
    GL_CHECK(glBufferData(buffer_target, size, data, usage));
}



RWBuffer<GraphicsAPI::GLESv3>::RWBuffer(long number, long each_size, const void * data) {
    GL_CHECK(glGenBuffers(1, &buffer));
    GL_CHECK(glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffer));
    if (data) {
        GL_CHECK(glBufferData(GL_SHADER_STORAGE_BUFFER, number * each_size, data, GL_DYNAMIC_DRAW));
    }
    GL_CHECK(glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0));
}